#include <iostream>
#include <algorithm>

using namespace std;
const int INT_MAX = 0x3f3f3f3f;
const int N = 100010;

int q[N];
int a, b;

bool check(int b, int mid){
    int sum = 0, cnt = 0;
    for(auto x:q){
        if(x > mid) return false;
        else if(sum + x > mid){
            cnt ++ ;
            sum  = x;

        }
        else sum += x;
    }
    if(sum) cnt ++;
    return cnt <= b;
}

int main(){
    cin >> a >> b;
    for(int i = 0 ; i < a ;i ++)
    {
        scanf("%d", &q[i]);

    }
    int l = 0, r = INT_MAX;
    while(l < r){
        int mid = (long long )l + r >> 1;
        if(check( b, mid)) r= mid;
        else l = mid + 1;
    }
    cout << r<< endl;

    return 0;
}